#ifndef SEGMENTATION_CPP
#define SEGMENTATION_CPP

#include "Segmentation.h"

/**
  * This class represents a segmented image.
  */

Segmentation::Segmentation(QImage * img)
{
    segmentedObjects = new QList<SegmentedObject *>;
    image = img;
}

Segmentation::~Segmentation(){}

QList<SegmentedObject *> * Segmentation::getSegmentedObjects() const
{
    return segmentedObjects;
}

void Segmentation::addSegmentedObject( SegmentedObject * segmObj )
{
    segmentedObjects->push_back(segmObj);
}

void Segmentation::setImage( QImage * img )
{
    image = img;
}

QImage * Segmentation::getImage()
{
    return image;
}

QImage * Segmentation::getRegionImage(bool useImageBackground, QColor color)
{
    QImage * regionImage;

    // Set the image as background accord to the option "useImageBackground"
    if ( useImageBackground )
        regionImage = new QImage(*image);
    else
    {
        regionImage = new QImage(image->size(), image->format());
        regionImage->fill( QColor(255,255,255).rgb()  );
    }

    SegmentedObject * segm;

    foreach(segm, *segmentedObjects)
    {
        QSet<int> * segmObject = segm->getSegmentedObject();

        int pixel;

        // Paint each pixel in the image
        foreach( pixel, *segmObject )
            regionImage->setPixel( Transformations::getX(regionImage, pixel), Transformations::getY(regionImage, pixel), color.rgb() );
    }

    return regionImage;
}

#endif // SEGMENTATION_CPP

